using System;
using System.Threading;
using GeoFramework.Gps.Nmea;
using GeoFramework.Gps.Emulators;

namespace GeoFramework.Examples
{
	/// <summary>
	/// Reperesents a customized GPS device emulator.
	/// </summary>
	public class CustomEmulator : GeoFramework.Gps.Emulators.NmeaEmulator 
	{
		/* The constructor specifies a name for the emulator.  This name is
		 * used as the name of the Thread when emulation is active.  The name
		 * should describe the device being emulated, and typically includes
		 * a support URL to assist developers.
		 */

		public CustomEmulator() : base("My custom device emulator (http://www.mycompany.com)")
		{
		}

		/* The DoEmulation method is responsible for generating the actual output 
		 * to send to listening clients.  This method is called on the emulation
		 * thread, so Thread.Sleep() statements are allowed and will not block the
		 * client application.  
		 * 
		 * For this example, we will send a single $GPRMC sentence describing the
		 * current position, speed, bearing and time to the client.  We will also
		 * send a second demo sentence to indicate that this is a custom emulator.
		 * 
		 * The NmeaEmulator class takes care of simulating realistic movement along
		 * a route.  This method should only generate output to the client, and not
		 * modify any information about the current location.
		 */ 

		protected override void OnEmulation()
		{
			// Build a $GPRMC sentence using the current simulated location, speed
			// and bearing. 
			GprmcSentence Output = new GprmcSentence(this.UtcDateTime,
				this.IsFixed, this.CurrentPosition, this.Speed, this.Bearing,
				Longitude.Empty);

			// Send the output to any listening clients
			WriteToClient(Output);

			// Also send a demo sentence just to prove this is working
			WriteToClient("It's easy to build a custom GPS device emulator.\r\n");

			// Sleep for one second before sending any more sentences
			Thread.Sleep(1000);
		}
	}
}
